<?php
class ArticlesController extends AppController{
	
	var $name = 'Articles';
	
// 后台增加 
	function admin_add() {
		$this->pageTitle = __("Add ".$this->modelClass, true);
		
		$modelClass = $this->modelClass;
		//$categorys = $this->Category->find('list');
		$categorys = $this->Category->generatetreelist();
		//$parents[''] = 'root';
		$newparents = array(''=>__('root',true));
		foreach($categorys as $k => $v)
		{
			$newparents[$k]=$v;
		}
		$categorys = $newparents;
		
		$this->set(compact('categorys'));
		
		if(empty($cate_id))
		{
			$cate_id=$this->_getParamVars('cate_id');
		}
		$this->set('cate_id',$cate_id);		
//		echo '<pre>';
//		print_r($this->params);
//		print_r($this->data);
//		exit;
        if (!empty($this->data)) {
        	$this->data['Article']['user_id'] = $this->currentUser['User']['id'];
        	
            $this->{$modelClass}->create();
            
            if ($this->{$modelClass}->save($this->data)) {
            	$this->data['CategoryData']['data_id'] = $this->{$modelClass}->getLastInsertID();
            	$this->data['CategoryData']['type'] = $modelClass;          	
            	$this->{$modelClass}->CategoryData->save($this->data);
            	
                $this->Session->setFlash(__('The User has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
                
            }
        }
    }
    
}